local datong = fk.CreateSkill{
    name = "ym2__datong",
    tags = { Skill.Lord, Skill.Permanent },
}
Fk:loadTranslationTable{
    ["ym2__datong"] = "大同",
    [":ym2__datong"] = "主公技，持恒技，主副将的朝代之间包含“宋”的角色即是男性，也是女性。",
}

-- 判断一个角色主副将的朝代之间包含“宋”
---@param player ServerPlayer|Player @ 目标
local function haveSong(player)
    local BeforeSong = {"xia","shang","zhou","yue","zheng","vei","ghan","zhao","yan","qi","qin","chu","han","xin","wei","shu","wu","qun","jin","jliang","liang","chen","sui","tang","houzhou"}--宋朝之前
    local DuringSong = {"liao","jin","song","xixia"}--宋朝时期

    local BeforeLiuSong = {"xia","shang","zhou","yue","zheng","vei","ghan","zhao","yan","qi","qin","chu","han","xin","wei","shu","wu","qun","jin"}--刘宋之前
    local DuringLiuSong = {"song","qi","liang","chen"}--刘宋时期

    local BeforeSongGuo = {"xia","shang","zhou"}--宋国之前
    local DuringSongGuo = {"yue","zheng","vei","song","jin","chu","yan","qi","qin"}--宋国时期

    if player.general == "" or player.deputyGeneral == "" then return false end
    local kingdom1, kingdom2 = Fk.generals[player.general].kingdom, Fk.generals[player.deputyGeneral].kingdom

    if table.contains(DuringSong,kingdom1) or table.contains(DuringSong,kingdom2) or
    table.contains(DuringLiuSong,kingdom1) or table.contains(DuringLiuSong,kingdom2) or
    table.contains(DuringSongGuo,kingdom1) or table.contains(DuringSongGuo,kingdom2) then return true end

    if (table.contains(BeforeSong,kingdom1) and not table.contains(BeforeSong,kingdom2)) or
    (table.contains(BeforeSong,kingdom2) and not table.contains(BeforeSong,kingdom1)) then
        --p("在宋朝")
        return true
    end--在宋朝

    if (table.contains(BeforeLiuSong,kingdom1) and not table.contains(BeforeLiuSong,kingdom2)) or
    (table.contains(BeforeLiuSong,kingdom2) and not table.contains(BeforeLiuSong,kingdom1)) then
        --p("在刘宋")
        return true
    end--在刘宋

    if (table.contains(BeforeSongGuo,kingdom1) and not table.contains(BeforeSongGuo,kingdom2)) or
    (table.contains(BeforeSongGuo,kingdom2) and not table.contains(BeforeSongGuo,kingdom1)) then
        --p("在宋国")
        return true
    end--在宋国

    return false
end
datong:addEffect(fk.AfterSkillEffect,{
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(datong.name) and #table.filter(player.room.alive_players,function (cp)
            return haveSong(cp) and cp.gender ~= General.Bigender
        end) > 0 and data.skill.name ~= datong.name
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local tos = table.filter(player.room.alive_players,function (cp)
            return haveSong(cp)
        end)
        room:doIndicate(player,tos)
        for _, cp in ipairs(tos) do
            room:setPlayerMark(cp,datong.name,1)
            room:setPlayerProperty(cp, "gender", General.Bigender)
        end
    end,
})
datong:addAcquireEffect(function (self, player, is_start)
    local room = player.room
    local tos = table.filter(player.room.alive_players,function (cp)
        return haveSong(cp)
    end)
    room:doIndicate(player,tos)
    for _, cp in ipairs(tos) do
        room:setPlayerMark(cp,datong.name,1)
        room:setPlayerProperty(cp, "gender", General.Bigender)
    end
end)
datong:addLoseEffect(function (self, player, is_death)
    for _, cp in ipairs(player.room.alive_players) do
        if cp:getMark(datong.name) ~= 0 then
            player.room:setPlayerMark(cp,datong.name,0)
            player.room:setPlayerProperty(cp, "gender", Fk.generals[player.general].gender)
        end
    end
end)
return datong